package com.wsl.springbootsecurity.config;

import com.wsl.springbootsecurity.repository.CustomUserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 14:49 2017/12/1
 * @Modified by:
 */
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
    @Bean
    UserDetailsService customUserService(){
        return new CustomUserService();
    }
    protected void configure(AuthenticationManagerBuilder auth) throws Exception{
        auth.userDetailsService(customUserService());
    }
    protected  void configure(HttpSecurity httpSecurity) throws Exception{
        httpSecurity.authorizeRequests().anyRequest().authenticated()//所有请求需要认证即登陆后才能访问
                .and().formLogin().loginPage("/login").permitAll()//定制登录行为，登录页面可任意访问
                .and().logout().permitAll();//定制注销行为 注销请求可以任意访问
    }
}